#!/usr/bin/python3
# -*- coding: UTF-8 -*-

import tushare as ts
import pandas as pd
import numpy as np
from pandas import Series, DataFrame

global STOCKS
STOCKS = [
    '000507',   # ZHUHAIGANG
    '002497',   # YAHUAJITUAN
    '000877',   # TIANSHANGUFEN
    '002302',   # XIBUJIANSHE
    '002307'    # BEIXINLUQIAO
]

def get_all_price():
    '''''process all stock'''
    global STOCKS
    df = ts.get_realtime_quotes(STOCKS)
    print(df)
    return df

def get_one_price(stock_code):
    list0 = [stock_code,]
    df = ts.get_realtime_quotes(list0)
    # print(df)
    indexWords = list(df)
    strList1 = []
    strList2 = []
    for key in indexWords:
        #print(key)
        if key == 'name':
            strList1.append(list(df[key])[0])
        elif key == 'a5_p':
            strList1.append(list(df[key])[0])
        elif key == 'date':
            strList1.append(list(df[key])[0])
        elif key == 'code':
            strList1.append(list(df[key])[0])
        elif key == 'dtype':
            strList1.append(list(df[key])[0])
        elif key == 'time':
            strList1.append(list(df[key])[0])
        else:
            #print(key+"=="+list(df[key])[0])
            strList2.append(float(list(df[key])[0]))
    #print(strList1)
    #print(strList2)
    return [strList1,strList2]



if __name__ == '__main__':
    [strList1,strList2] = get_one_price('000507')
    print(strList1)
    print(strList2)


